home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM BV3 / BMUG PD-ROM Version BV3 (CDRM1097900).iso / Programming / Programming Languages / Pocket Forth 6 / Source / Interface.txt < prev    next >
Encoding:
Text File  |  1992-05-18  |  16.6 KB  |  631 lines  |  [TEXT/McSk]

  1. ; Interface.txt -- interface routines  3:37:12 PM  2/4/87
  2. ; Fri Jan 22, 1988 12:52:12 version 0.3
  3. ; Fri Feb 12, 1988 13:35:10 3+ menus
  4. ; Wed Mar 30, 1988 13:37:36 'newer' routine
  5. ; Thu Apr 07, 1988 16:00:59 nested loads
  6. ; Mon Apr 18, 1988 14:06:09 restructure variables, echo
  7. ; Sun May 01, 1988 10:38:11 fix emptyFS to skip nil handles
  8. ; Mon May 27, 1991 17:41:00 use wne based event loop and zoomin&out handlers
  9. ; Fri May 30, 1991 05:09:00 handler for "high level events"
  10. ; Sun Apr 12, 1992 22:48:00 move tib and userVars from ainterp
  11. ; Sun Apr 19, 1992 23:24:00 apple events
  12.  
  13. theWindow:    DC.L    0        ; pointer  ( 0 +md )
  14.     WContRect:    DC.W    0,0        ; ( 4 +md )
  15.     WSize:    DC.W    WHeight,WWidth    ; ( 8 +md )
  16.  
  17. Activate:    DC.W    drop-Base    ; ( 12 +md )
  18. Update:        DC.W    curs-Base    ; ( 14 +md )
  19. Button:        DC.W    beep-Base    ; ( 16 +md )
  20. YourMenu:    DC.W    menus-Base    ; ( 18 +md )
  21. Runner:        DC.W    null-Base    ; ( 20 +md )
  22. Closer:        DC.W    bye-Base    ; ( 22 +md )
  23. About:        DC.W    doabout-base    ; ( 24 +md )
  24. Newer:        DC.W    null-base    ; ( 26 +md )
  25. Echo:        DC.W    -1        ; ( 28 +md )
  26.  
  27. AppleMenu:    DC.L    0        ; ( 30 +md )
  28. FileMenu:    DC.L    0        ; ( 34 +md )
  29. EditMenu:    DC.L    0        ; ( 38 +md )
  30.  
  31. TextO:        DC.L    0        ; TextOffset ( 42 +md )
  32. TextE:        DC.L    0        ; TextEnd
  33. TextH:        DC.L    0        ; TextHandle
  34. FStack:        DCB.L    5,0        ; text block handles
  35. FOfsets:    DCB.L    5,0        ; text block offsets
  36. FEnds:        DCB.L    5,0        ; text block ends
  37. FSPtr:        DC.W    -4        ; file stack pointer
  38.         
  39. Events:        DC.W    Null-Base    ; Null Event ( 116 +md )
  40.         DC.W    BDEvt-Base    ; Mouse button down ( 118 +md )
  41.         DC.W    Null-Base    ; Mouse button up ( 120 +md )
  42.         DC.W    KeyEvt-Base    ; Key down ( 122 +md )
  43.         DC.W    Null-Base    ; Key up ( 124 +md )
  44.         DC.W    KeyEvt-Base    ; Auto key ( 126 +md )
  45.         DC.W    UDEvt-Base    ; Update window ( 128 +md )
  46.         DC.W    Null-Base    ; Disk inserted event ( 130 +md )
  47.         DC.W    ActEvt-Base    ; Activate window ( 132 +md )
  48.         DC.W    Null-Base    ; reserved ( 134 +md )
  49.         DC.W    doAEvent-Base    ; do AppleEvent ( 136 +md )
  50.         DC.W    Null-Base    ; I/O driver ( 138 +md )
  51.         DC.W    Null-Base    ; Undefined1 ( 140 +md )
  52.         DC.W    Null-Base    ; Undefined2 ( 142 +md )
  53.         DC.W    Null-Base    ; Undefined3 ( 144 +md )  ( v 146 +md )
  54.         DC.W    MFEvt-Base    ; MultiTask: mouse moved & suspend/resume - do nothing
  55.  
  56. EventRecord:
  57.   What:        DC.W    0        ; WhatEvent# ( 148 +md )
  58.   Message:    DC.W    0        ; key code, wptr, etc. ( 150 +md )
  59.    ASCII:    DC.W    0        ; ASCII code 
  60.   When:        DC.L    0        ; Ticks since startup ( 154 +md )
  61.   Where:                ; Mouse coordinates ( 158 +md )
  62.    V:        DC.W    0
  63.    H:        DC.W    0
  64.   Modify:    DC.W    0        ; State of modifier keys ( 162 +md )
  65.  
  66. WWindow:    DC.L    0        ; WindowPtr from FindWindow ( 164 +md )
  67. Clicks:        DC.W    Null-Base    ; InDesk ( 168 +md )
  68.         DC.W    MenuBar-Base    ; InMenu Bar ( 170 +md )
  69.         DC.W    DARgn-Base    ; InSystem Window ( 172 +md )
  70.         DC.W    ContentRgn-Base    ; InContent region ( 174 +md )
  71.         DC.W    DragRgn-Base    ; InDrag region ( 176 +md )
  72.         DC.W    Null-Base    ; InGrow region ( 178 +md )
  73.         DC.W    CloseRgn-Base    ; ByeByeBox ( 180 +md )
  74.         DC.W    beep-base    ; inZoomIn ( 182 +md )
  75.         DC.W    beep-base    ; inZoomOut ( 184 +md )
  76.  
  77. MFlag:        DC.W    0        ; true if multitasking ( 186 +md )
  78. AEvents:    DC.W    ae1-base    ; address of first AEentry ( 188 +md )
  79. AError:        DC.W    drop-base    ; process AEerror number ( 190 +md )
  80. KFlag:        DC.W    0        ; key flag  ( 192 +md )
  81. doneFlag:    DC.W    0        ; done flag  ( 194 +md )
  82. openFlag:    DC.W    0        ; open flag  ( 196 +md )
  83. AEReply:    DC.L    0        ; Apple Event Reply ( 198 +md )
  84. AEEventRecord:    DC.L    0        ; Apple Event Event Record ( 202 +md )
  85.  
  86. ; addresses beyond this are not documented relative to +md
  87. oldIdle:    DC.W    0
  88. Desc:        DC.L    0,0
  89. Scratch:    DC.L    0
  90. SaveAERegs:    DC.L    0,0,0,0        ; Dict,DP,IS,PS
  91. BigRect:    DC.W    $8000,$8000,$7FFF,$7FFF        ; for dragging
  92.  
  93.     ae1:    DC.L    'aevt'
  94.         DC.L    'oapp'
  95.         DC.W    aenull-base
  96.         DC.W    ae2 -base
  97.     ae2:    DC.L    'aevt'
  98.         DC.L    'odoc'
  99.         DC.W    aeopen-base
  100.         DC.W    ae3 -base
  101.     ae3:    DC.L    'aevt'
  102.         DC.L    'pdoc'
  103.         DC.W    aenull-base
  104.         DC.W    ae4 -base
  105.     ae4:    DC.L    'aevt'
  106.         DC.L    'quit'
  107.         DC.W    aebye-base,0
  108.  
  109. Menus:        DC.W    Fmenu-base
  110.         DC.W    Emenu-base
  111.     Fmenu:    DC.W    open-base    ; Open…
  112.         DC.W    null-base    ; -
  113.         DC.W    csave-base    ; Save
  114.         DC.W    mon-base    ; Debug
  115.         DC.W    null-base    ; -
  116.         DC.W    beep-base    ; Print
  117.         DC.W    null-base    ; -
  118.         DC.W    by-base        ; Quit
  119.     Emenu:    DC.W    beep-base    ; Undo
  120.         DC.W    null-base    ; -
  121.         DC.W    beep-base    ; Cut
  122.         DC.W    beep-base    ; Copy
  123.         DC.W    paste-base    ; Paste
  124.         DC.W    beep-base    ; Clear
  125.  
  126. ; addresses beyond this are relative to tib
  127. TermBuf        DCB.B    82,32        ; command line buffer
  128.  
  129. ; User variables
  130. StackSize:    DC.W    2048        ; variable stack size
  131. IntA7:        DC.L    0        ; initial value for A7
  132. Rzero:        DC.L    0        ; value for A7 after linking
  133. Szero:        DC.L    0        ; bottom of stack
  134. Form:        DC.L    $FFFF0007    l decaform record
  135. Expand:        DC.L    0        ; hold address of expand routine
  136. FreePt:        DC.W    dictend-Base    ; initial compile point freespace
  137. FreeSz:        DC.W    base+32767-dictend    ; max headroom
  138. DictPt:        DC.W    task-theLink    ; initial dict. search start
  139. NBase:        DC.W    10        ; the numeric radix
  140. Held:        DC.W    0        ; the HLD data
  141. DoesAddr:    DC.L    0        ; "does>" jump address
  142. fcolon:        DC.B    0        ;   compile mode
  143. fimmed:        DC.B    0        ;   immediate flag
  144. fneg:        DC.B    0        ;   negative flag
  145. fint:        DC.B    $80        ;   interactive mode
  146. fmacro:        DC.W    0        ;   macro flag+filler
  147.  
  148. ; ----- Startup Code -----
  149.  
  150. MacStart:    ; load the menus, setup a window and create a data block
  151.     MOVEQ    #1,D3
  152.     @0: CLR.L    -(SP)            ; room
  153.     MOVE    D3,-(SP)        ; Push menu ID
  154.     _GetRMenu            ; Get menu from resource.
  155.     MOVE    D3,D0
  156.     SUBQ    #1,D0
  157.     ASL    #2,D0
  158.     LEA     AppleMenu,A0        ; menu handle data area
  159.     MOVE.L    (SP),0(A0,D0.W)        ; Save it.
  160.     CLR    -(SP)            ; Push a 0 for append.
  161.     _InsertMenu
  162.     ADDQ    #1,D3
  163.     CMP    #4,D3
  164.     BNE.S    @0            ; do the next menu
  165.  
  166.     MOVE.L    AppleMenu,-(SP)
  167.     MOVE.L    #'DRVR',-(SP)        ; Load all DRVR resource types.
  168.     _AddResMenu            ; Add the DA's.
  169.     _DrawMenuBar
  170.  
  171.     ; create a window
  172.     CLR.L    -(SP)            ; make room for the new window pointer
  173.     MOVE    #128,-(SP)        ; WIND ID
  174.     CLR.L    -(SP)            ; put it on the heap
  175.     MOVE.L    #-1,-(SP)        ; behind none
  176.     MOVE.L    #'qd  ',-(PS)
  177.     JSR    qgestalt-base(BP)
  178.     TST    (PS)+
  179.     BEQ.S    @1
  180.     MOVE.L    (PS)+,D0
  181.     CMP    #$100,D0
  182.     BLT.S    @1
  183.     _GetNewCWindow
  184.     BRA.S    @2
  185.     @1:    _GetNewWindow
  186.     @2:    MOVE.L  (SP),theWindow-base(BP)
  187.     MOVE.L    (SP),-(SP)
  188.     MOVE.L    WSize-base(BP),-(SP)
  189.     CLR.W    -(SP)
  190.     _SizeWindow
  191.     MOVE.L    (SP),-(SP)
  192.     _ShowWindow
  193.     _SetPort
  194.     
  195.     ; create a temp scrap holder
  196.     MOVE.L    #10,D0            ; this is just a size
  197.     _NewHandle            ; create a handle
  198.     MOVE.L    A0,TextH-base(BP)    ; to hold clipboard data
  199.  
  200.     ; Check for multitasking environment
  201.     CLR    MFlag-base(BP)        ; set MFlag to 0
  202.     MOVE.W    #$A89F, D0        ; _Unimplemented
  203.     _GetTrapAddress            ; NGetTrapAddress
  204.     MOVE.L    A0,D1
  205.     MOVE.W    #$A860,D0        ; _WaitNextEvent
  206.     _GetTrapAddress            ; NGetTrapAddress
  207.     CMP.L    A0,D1
  208.     BEQ.S    @3            ; no multitasking
  209.     MOVE.W    #$100,MFlag-base(BP)    ; set multitasking flag
  210.  
  211.     ; install apple event handlers if running system 7
  212.     @3:    MOVE.L    #'evnt',-(PS)
  213.     JSR    QGestalt-base(BP)
  214.     TST    (PS)+            ; check for gestalt
  215.     BEQ.S    @5            ; no gestalt, just return
  216.     SUBQ.L    #1,(PS)+        ; check for apple events present
  217.     BNE.S    @5            ; no apple events, just return
  218.     MOVE    AEvents-base(BP),D0    ; start rel addr of the events list
  219.     @4:    LEA    0(BP,D0.W),A4        ; start addr of an item
  220.     CLR    -(A7)            ; result
  221.     MOVE.L    (A4),-(A7)        ; push event class
  222.     MOVE.L    4(A4),-(A7)        ; push event selector
  223.     MOVE    8(A4),D0        ; get rel addr of handler
  224.     PEA    0(BP,D0.W)        ; push abs addr of handler
  225.     PEA    (BP)            ; push refcon
  226.     CLR    -(A7)            ; not syshandler
  227.     _AEInstallEvent        ; INSTALL EACH EVENT IN THE LIST
  228.     TST    (A7)+            ; drop result
  229.     MOVE    10(A4),D0        ; get rel addr of next item
  230.     BNE.S    @4            ; a zero indicates done
  231.  
  232.     @5:    RTS
  233.  
  234.  
  235. ; ----- Event Loop ------
  236.  
  237. doDone:    MOVEA.L    intA7-base(BP),A7    ; *** quit PocketForth ***
  238.     RTS
  239.  
  240. doOpen:    CLR    openFlag-base(BP)
  241.     JMP    doload-base(BP)
  242.      RTS
  243.  
  244. NextEvent:
  245.     CLR    KFlag-base(BP)        ; clear the key flag
  246.     CLR    -(SP)            ; turn all menus white
  247.     _HiLiteMenu
  248.  
  249.     TST    doneFlag-base(BP)
  250.     BNE.S    dodone
  251.  
  252.      TST    openFlag-base(BP)
  253.      BNE.S    doopen
  254.  
  255.     MOVE    Runner-base(BP),D0
  256.     JSR    0(BP,D0.W)        ; run the idle routine
  257.  
  258.     MOVE.L    #-1,-(SP)
  259.     PEA    EventRecord-base(BP)    ; event record to be filled
  260.  
  261.     TST    MFlag-base(BP)        ; running multitasking?
  262.     BNE.S    @1            ; if not, do SystemTask/GetNextEvent
  263.  
  264.     _SystemTask            ; handle DA's, etc.
  265.     _GetNextEvent            ; fill the event record
  266.     BRA.S    @2
  267.  
  268.     @1:    CLR.L    -(SP)            ; 0 sleep ticks
  269.     CLR.L    -(SP)            ; nil mouse region
  270.     _WaitNextEvent            ; get multitasking event
  271.  
  272.     @2:    TST    (SP)+            ; Is this an event?
  273.     BEQ.S    rdr            ;   no  this is a non-event
  274.  
  275.     MOVE    What-base(BP),D0    ; get event number
  276.     CMPI    #23,D0            ; is it a HighLevelEvent?
  277.     BNE.S    @3
  278.     MOVEQ    #10,D0            ; remap HLEs to event 10 (IM VI5-12)
  279.  
  280.     @3:    LEA    Events-base(BP),A0
  281.   hop1:    ADD    D0,D0            ; Calculate and jump to the ...
  282.     MOVE    0(A0,D0.W),D0        ; ... rel addr of the routine ... 
  283.   hop2:    JMP    0(BP,D0.W)        ; ... in the Events list.
  284.  
  285. ; -- Mouse Down Event --
  286.  
  287. BDEvt:    CLR    -(SP)            ; Result of find window
  288.     MOVE.L    Where-base(BP),-(SP)    ; Mouse point of click.
  289.     PEA    WWindow-base(BP)    ; Var. for pointer of clicked wind.
  290.     _FindWindow            ; Returns window region code ...
  291.     CLR.L    D0            ; ... (see p. WM-27 in IM).
  292.     MOVE    (SP)+,D0        ; Pop part number
  293.     LEA    Clicks-base(BP),A0    ; clicks is an array of rel.addrs
  294.     BRA.S    hop1
  295.  
  296.     MenuBar:
  297.     CLR.L    -(SP)            ; Make room for menu choice data.
  298.     MOVE.L    Where-base(BP),-(SP)    ; Mouse coordinates of click.
  299.     _MenuSelect            ; Get the selected Menu data.
  300.     MOVE.L    (SP)+,-(PS)        ; menu ID and item to pstack.
  301.     JMP    DoMenu-base(BP)
  302.         
  303.     DARgn:
  304.     PEA    EventRecord-base(BP)
  305.     MOVE.L    WWindow-base(BP),-(SP)
  306.     _SystemClick
  307.     RTS
  308.     
  309.     DragRgn:
  310.     MOVE.L    WWindow-base(BP),-(SP)    ; push The Window Pointer
  311.     MOVE.L    Where-base(BP),-(SP)    ; push The Mouse Coordinates
  312.     PEA    BigRect-base(BP)    ; The drag boundry limits
  313.     _DragWindow            ; Drag it
  314.    rdr:    RTS
  315.  
  316.     CloseRgn:
  317.     CLR    -(SP)
  318.     MOVE.L    WWindow-base(BP),-(SP)
  319.     MOVE.L    Where-base(BP),-(SP)
  320.     _TrackGoAway
  321.     MOVE    (SP)+,D0
  322.     BEQ.S    rdr
  323.     by:    MOVE    Closer-base(BP),D0    ; inital value: bye-base
  324.     BRA.S    hop2
  325.  
  326.     ContentRgn:                ; select the clicked in window.
  327.     MOVE.L    WWindow-base(BP),-(SP)
  328.     _SelectWindow
  329.     MOVE    Button-base(BP),D0    ; inital value: beep-base
  330.     BRA.S    hop2
  331.  
  332. ; -- Key Down Event --
  333.  
  334. KeyEvt:    _ObscureCursor
  335.     MOVE    Message+2-base(BP),D0
  336.     AND    #$FF,D0            ; D0 has the ASCII code of the key.
  337.     MOVE    Modify-base(BP),D1
  338.     BTST    #8,D1
  339.     BNE.S    CommandKey
  340.     MOVE    D0,kflag-base(BP)
  341.     RTS
  342.  
  343. ; Menu actions
  344.     CommandKey:                ; handle the menu choices.
  345.     CLR.L    -(SP)            ; Room for menu data.
  346.     MOVE    D0,-(SP)        ; Push ASCII.
  347.     _MenuKey            ; Get the menu data.
  348.     MOVE.L    (SP)+,-(PS)        ; menu ID and item to pstack.
  349.     
  350.     DoMenu:    ; Determine which menu was used.
  351.     TST    2(PS)            ; is the item number = 0?
  352.     BEQ    twodrop            ; no menu selection, drop data
  353.     
  354.     CMPI    #1,(PS)            ; Is it the Apple menu? ...
  355.     BEQ.S    DoAppleMenu        ; handle this special case
  356.  
  357.     CMPI    #3,(PS)            ; Is it the Edit menu?
  358.     BNE.S    @0            ; the last special case *
  359.     
  360.     CLR.L    -(SP)            ; Check if it's a DA window
  361.     _FrontWindow
  362.     MOVE.L    (SP)+,A0
  363.     TST    $6C(A0)            ; windowKind(FrontWindow)
  364.     BGE.S    @0            ; negative=dawindow
  365.  
  366.     TST    (PS)+            ; drop the menu id
  367.     CLR    -(SP)
  368.     MOVE    (PS)+,-(SP)        ; push item-1
  369.     SUBQ    #1,(SP)
  370.     _SysEdit            ; do the da edit stuff
  371.     TST    (SP)+
  372.     RTS
  373.  
  374.     @0:    MOVE    YourMenu-base(BP),D0    ; inital value:
  375.     LEA    0(BP,D0.W),A0        ; do a double indexed reference
  376.     MOVE    (PS)+,D0
  377.     SUBQ    #2,D0
  378.     ADD    D0,D0
  379.     MOVE    0(A0,D0.W),D0
  380.      LEA    0(BP,D0.W),A0
  381.     MOVE    (PS)+,D0
  382.     SUBQ    #1,D0
  383.     JMP    hop1-base(BP)
  384.  
  385. DoAppleMenu:
  386.     CLR    (PS)+
  387.     MOVE    (PS)+,D1
  388.     CMP    #1,D1            ; Is it the first item?
  389.     BNE.S    @0
  390.     MOVE    about-base(BP),D0
  391.     JMP    0(BP,D0.W)
  392.     @0:    PEA    WWindow            ; Its a DA
  393.     _GetPort
  394.     MOVE.L    AppleMenu-base(BP),-(SP)
  395.     MOVE    D1,-(SP)
  396.     PEA    (A2)            ; name at here
  397.     _GetItem
  398.     CLR    -(SP)
  399.     PEA    (A2)
  400.     _OpenDeskAcc
  401.     MOVE    (SP)+,D0
  402.     MOVE.L    WWindow-base(BP),-(SP)
  403.     _SetPort
  404.     RTS
  405.  
  406. DoAbout:
  407.     CLR    -(SP)            ; Room for which item number.
  408.     MOVE    #257,-(SP)        ; Resource ID of AboutDialog
  409.     CLR.L    -(SP)
  410.     _Alert                ; About Item
  411.     CLR    (SP)+            ; Don't care which item dismissed.
  412.     RTS
  413.  
  414. ; -- Update Event --
  415.  
  416. UDEvt:    PEA    WWindow-base(BP)
  417.     _GetPort
  418.     MOVE.L    WWindow-base(BP),-(SP)    ; push for _SetPort
  419.     MOVE.L    Message-base(BP),-(SP)    ; push wpointer for _EndUpdate
  420.     MOVE.L    (SP),-(SP)        ; push for _SetPort
  421.     MOVE.L    (SP),-(SP)        ; push for _BeginUpdate
  422.     _BeginUpdate            ; restrict to invalid region
  423.     _SetPort            ; specify this window
  424.     MOVE    Update-base(BP),D0    ; inital value: curs-base
  425.     JSR    0(BP,D0.W)        ; execute the draw routine
  426.     _EndUpdate            ; go back to current cliprgn
  427.     _SetPort
  428.     RTS
  429.  
  430. ; -- Activate Event --
  431.  
  432. ActEvt:
  433.     CLR    -(PS)            ; modify has on/off flag in bit 0
  434.     BTST    #0,Modify+1-base(BP)
  435.   act1:    BEQ.S    @0
  436.     SUBQ    #1,(PS)
  437.     @0:    MOVE    Activate-base(BP),D0    ; inital value: drop
  438.     JMP    0(BP,D0.W)
  439.  
  440. ; ---- Activate/Suspend ----
  441.  
  442. MFEvt:    CLR    -(PS)
  443.     TST    message-base(BP)
  444.     BMI    drop
  445.     BTST    #0,message+3-base(BP)
  446.     BRA.S    act1
  447.  
  448. ; ---- High Level Event ----
  449.  
  450. DoAEvent:
  451.     MOVEM.L    Dict/DP/IS/PS,saveAERegs-base(BP) ; send along PF's regs
  452.     CLR    -(SP)
  453.     PEA    eventRecord-base(BP)
  454.     _AEProcessAppleEvent
  455.     MOVE    (SP)+,-(PS)
  456.     BEQ.S    noaer
  457.     MOVE    AError-base(BP),D0
  458.     JMP    0(BP,D0.W)
  459.  noaer:    MOVEM.L    saveAERegs-base(BP),Dict/DP/IS/PS ; update PF's regs
  460.     RTS
  461.  
  462. aepre:    MOVEM.L    (SP)+,A0/A1/BP
  463.     MOVE.L    (SP)+,AEReply-base(BP)        ; store reply
  464.     MOVE.L    (SP)+,AEEventRecord-base(BP)    ; store event record
  465.     CLR    (SP)                ; return no error
  466.     MOVE.L    A1,-(SP)            ; re-stack the return addr
  467.     MOVEM.L    Dict/DP/IS/PS,-(SP)        ; stash the system regs
  468.     MOVEM.L    saveAERegs-base(BP),Dict/DP/IS/PS  ; load PF regs
  469.     JMP    (A0)
  470.  
  471. aenull:    BSR.S    aepre
  472.   aert:    BSR.S    aepost
  473.     RTS
  474.  
  475. aebye:    BSR.S    aepre
  476.     JSR    by-base(BP)
  477.     BRA.S    aert
  478.  
  479. aeopen:    BSR.S    aepre
  480.     BSR.S    aeopn
  481.     BRA.S    aert
  482.  
  483. aepost:    MOVE.L    (SP)+,A0
  484.     MOVEM.L    Dict/DP/IS/PS,saveAERegs-base(BP)  ; save PF regs
  485.     MOVEM.L    (SP)+,Dict/DP/IS/PS    ; restore the system regs
  486.     JMP    (A0)
  487.  
  488. aeopn:    CLR    -(SP)
  489.     MOVE.L    AEEventRecord-base(BP),-(SP)
  490.     MOVE.L    #'----',-(SP)
  491.     MOVE.L    #'list',-(SP)
  492.     PEA    desc-base(BP)
  493.     _AEGetParamDesc
  494.     TST    (SP)+
  495.     BNE.S    @0
  496.     MOVE    runner-base(bp),oldidle-base(BP)
  497.     MOVE    #odocidle-base,runner-base(BP)
  498.     @0:    RTS
  499.  
  500. OdocIdle:    ; Open the document in the idle handler
  501.     MOVE    oldIdle-base(bp),runner-base(BP)    ; reset old handler
  502.     CLR    -(SP)
  503.     PEA    desc-base(BP)
  504.     CLR.L    -(SP)
  505.     ADDQ.L    #1,(SP)
  506.     MOVE.L    #'fss ',-(SP)
  507.     PEA    108(A2)
  508.     PEA    112(A2)
  509.     PEA    34(A2)
  510.     MOVE.L    #70,-(SP)
  511.     PEA    104(A2)
  512.     _AEGetNthPtr            ; Get fssPtr at here + 34
  513.     TST    (SP)+
  514.     BNE.S    @1
  515.  
  516.     ; clear out a buffer for working directory param. block
  517.     LEA    40+64+80(A2),A0
  518.     MOVE    #19,D0
  519.     @0:    CLR.L    -(A0)
  520.     DBRA    D0,@0
  521.  
  522.     ; calc working directory here
  523.     MOVE    34(A2),22(A0)        ; -> ioVRefNum
  524.     MOVE.L    36(A2),48(A0)        ; -> ioWDDirID
  525.     _OpenWD
  526.     MOVE    22(A0),-(PS)        ; <- working directory
  527.  
  528.     ADDQ    #1,openFlag-base(BP)
  529.  
  530.     @1:    CLR    -(SP)            ; Be neat
  531.     PEA    desc-base(BP)
  532.     _AEDisposeDesc
  533.     ADDQ.L    #2,SP
  534.     RTS
  535.  
  536. ; Pasting support
  537.  
  538. ClearTermBuf:
  539.     MOVEQ    #76,D0
  540.     LEA    TermBuf-base(BP),IS
  541.     @0:    MOVE.L    #$20202020,0(IS,D0)    ; fill line buffer with blanks
  542.     SUBQ.B    #4,D0
  543.     BGE.S    @0
  544.     RTS
  545.  
  546. EmptyFS: ; clear pending loads from the file stack
  547.     TST    fsptr-base(BP)
  548.     BMI.S    @1
  549.     LEA    fstack-base(BP),A1
  550.     MOVE    fsptr-base(BP),D0
  551.     MOVE.L    0(A1,D0.W),A0        ; A0 has the next load block addr
  552.     MOVE.L    A0,D1
  553.     BEQ.S    @0            ; dont try to dispose of nil handle
  554.     CLR.L    0(A1,D0.W)
  555.     CMPA.L    TextH-base(BP),A0
  556.     BEQ.S    @0
  557.     _DisposHandle
  558.     @0:    SUBQ    #4,fsptr-base(BP)
  559.     BRA.S    emptyfs
  560.     @1:    RTS
  561.  
  562. Paste:    JSR    nocurs-base(BP)
  563.     CLR.L    -(SP)
  564.     MOVE.L    TextH-base(BP),-(SP)    ; handle to the scrap data
  565.     MOVE.L    #'TEXT',-(SP)
  566.     PEA    TextO-Base(BP)
  567.     _GetScrap
  568.     MOVE.L    (SP)+,TextE-base(BP)    ; put the length at TextE
  569.     MOVE.L    TextH-base(BP),A0    ; get a handle to the scrap data
  570.     MOVE.L    (A0),D0            ; derefrence the scrap handle
  571.     MOVE.L    D0,TextO-base(BP)    ; set TextO to start of scrap data
  572.     ADD.L    D0,TextE-base(BP)    ; set TextE to end of scrap data
  573.     _HLock                ; don't let data move during paste
  574.     CLR    fsptr-base(BP)
  575.     MOVE.L    TextH-base(BP),fstack-base(BP)
  576.     MOVE.L    TextO-base(BP),fofsets-base(BP)
  577.     MOVE.L    TextE-base(BP),fends-base(BP)
  578.     go:    CLR.B    fint-base(BP)        ; leave keyboard mode
  579.     JMP    CRet-base(BP)        ; get next line
  580.  
  581. Pasting:    ; GetInput comes here for input when fint-base(BP) is 0
  582.     JSR    ClearTermBuf-base(BP)
  583.     CLR.L    D1            ; clear the character count
  584.     CLR.L    D0            ; and the character
  585.     MOVE.L    TextO-base(BP),A0    ; set the input address
  586.     @0:    MOVE.B    0(A0,D1.W),D0        ; BEGIN  get a character
  587.     CMP.B    #CR,D0            ;     is it not a CR?
  588.     BEQ.S    @1
  589.     CMPI.B    #78,D1            ;     or 78 characters in buffer
  590.     BGE.S    @1            ; WHILE
  591.         MOVE.B    D0,0(IS,D1)        ;     stash it into buffer
  592.     ADDQ.B    #1,D1            ;     increment count
  593.     BRA.S    @0            ; REPEAT
  594.     @1:    ADDQ.B    #1,D1            ; increment count
  595.     MOVE.B    #CR,0(IS,D1)        ; stash CR into buffer
  596.     MOVE    D1,-(PS)        ; preserve count for TYPE
  597.     ADD.L    TextO-base(BP),D1
  598.     MOVE.L    D1,TextO-base(BP)
  599.     CMP.L    TextE-base(BP),D1    ; IS the block done (TextO>TextE)?
  600.     BMI.S    tandr            ; just type and return if not.
  601.     
  602.     MOVE    fsptr-base(BP),D0
  603.     LEA    fstack-base(BP),A0
  604.     MOVE.L    0(A0,D0.W),A0
  605.     _HUnlock            ; unlock the block
  606.     BMI    huh
  607.     CMPA.L    TextH-base(BP),A0
  608.     BEQ.S    @2            ; keep the scrap block
  609.     _DisposHandle            ; dispose of loaded blocks
  610.     BMI    huh
  611.  
  612.     @2:    SUBQ    #4,fsptr-base(BP)    ; pop fstack
  613.     BMI.S    @3            ; branch if no pending loads
  614.  
  615.     MOVE    fsptr-base(BP),D0
  616.     LEA    fofsets-base(BP),A0    ; set TextO to (fofsets+fsptr)
  617.     MOVE.L    0(A0,D0.W),TextO-base(BP)
  618.     LEA    fends-base(BP),A0
  619.     MOVE.L    0(A0,D0.W),TextE-base(BP)
  620.     BRA.S    tandr
  621.  
  622.     @3:    BSET.B    #7,fint-base(BP)    ; set keyboard mode
  623.  tandr:    TST    echo-base(BP)
  624.     BNE.S    @4
  625.     JMP    drop-base(BP)
  626.     
  627.     @4:    MOVE    #termbuf-base,-(PS)
  628.     JSR    swapp-base(BP)
  629.     JSR    type-base(BP)
  630.     JMP    doCR-base(BP)        ; TIB count TYPE CR ;
  631.